package org.one.stone.soup.grfxML;

import org.one.stone.soup.mjdb.data.field.IntField;
import org.one.stone.soup.mjdb.data.field.LockException;
  /*
 * Copyright 2000-2001 Wet-Wired.com Ltd.,
 * Portsmouth England
 * All rights reserved.
 */

/**
	*
	* @author Nik Cross
*/
public class GeometryProcessor {
public static void process(DataRectangle rectangle)
{
 try{
	DataPoint topRight = new DataPoint();
	topRight.setValueX( rectangle.end.getValueX() ,rectangle);
	topRight.setValueY( rectangle.start.getValueY() ,rectangle);

	DataPoint bottomLeft = new DataPoint();
	bottomLeft.setValueX( rectangle.start.getValueX() ,rectangle);
	bottomLeft.setValueY( rectangle.end.getValueY() ,rectangle);

	rectangle._points.setEmpty();

	 rectangle._points.add(rectangle.start ,rectangle);
	 rectangle._points.add(topRight ,rectangle);
	 rectangle._points.add(rectangle.end ,rectangle);
	 rectangle._points.add(bottomLeft ,rectangle);

  }catch(LockException le){}//dummy catch
}
public static void process(DataRPolygon rPoly)
{
 try{
	rPoly._points.setEmpty();

	int deg = 0;
	IntField degF = new IntField();
	degF.setValue(deg,rPoly);

	DataPoint p = new DataPoint();
	p.setValueX(rPoly.radius.getValue(),rPoly);

	for(int loop=0;loop<rPoly.sides.getValue();loop++)
	{
		DataPoint np = new DataPoint();
/*		if( !NameHelper.isSystemName( rPoly.points.getId() ) )
			np.setId(rPoly.points.getId()+"["+loop+"]",rPoly);*/
		GrfxMLProcessor.rotate(p,degF,np);
		rPoly._points.add(np,rPoly);

		deg+=( 360/rPoly.sides.getValue() );
		degF.setValue(deg,rPoly);
	}
 }catch(LockException le){}//dummy catch
}
public static void process(DataStar star)
{
 try{
	star._points.setEmpty();

	int deg = 0;
	int deltaDeg = (180/star.sides.getValue());

	IntField degF = new IntField();
	degF.setValue(deg,star);

	DataPoint pA = new DataPoint();
	pA.setValueX(star.radiusA.getValue(),star);

	DataPoint pB = new DataPoint();
	pB.setValueX(star.radiusB.getValue(),star);

	for(int loop=0;loop<star.sides.getValue();loop++)
	{
		DataPoint np = new DataPoint();

		deg= 360*loop/star.sides.getValue();
		degF.setValue(deg,star);

		GrfxMLProcessor.rotate(pA,degF,np);
		star._points.add(np,star);

		deg=deg+deltaDeg ;
		degF.setValue(deg,star);

		np = new DataPoint();
		GrfxMLProcessor.rotate(pB,degF,np);
		star._points.add(np,star);
	}
 }catch(LockException le){}//dummy catch
}
}
